package com.buydeem.observer;

import java.util.ArrayList;
import java.util.List;

/**
 * 刘德华话题
 *
 * @author zengchao
 * @date 2022-04-19 16:08:08
 */
public class LdhSubject implements Subject {

    private final List<Observer> observers = new ArrayList<>();

    @Override
    public void registerObserver(Observer observer) {
        observers.add(observer);
    }

    @Override
    public boolean removeObserver(Observer observer) {
        int index = observers.indexOf(observer);
        if (index != -1){
            observers.remove(index);
            return true;
        }
        return false;
    }

    @Override
    public void notifyObservers(String msg) {
        for (Observer observer : observers) {
            observer.update(msg);
        }
    }
}
